package com.yanqu.road.server.cmd.activity.yuanbaolottery;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ApprenticeProto;
import com.yanqu.road.pb.activity.YuanBaoLotteryProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.apprentice.ApprenticeModule;
import com.yanqu.road.server.gameplayer.module.activity.yuanbaolottery.YuanBaoLotteryModule;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.Map;

@CmdApi(reqMsg = YuanBaoLotteryProto.YuanBaoLotteryGetReqMsg.class, respMsg = YuanBaoLotteryProto.YuanBaoLotteryGetReqMsg.class)
@Cmd(code = Protocol.S_YUANBAO_LOTTERY_GET, desc = "抽奖")
public class YuanBaoLotteryCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        YuanBaoLotteryProto.YuanBaoLotteryGetReqMsg reqMsg = YuanBaoLotteryProto.YuanBaoLotteryGetReqMsg.parseFrom(packet.getBytes());
        ret = player.getModule(YuanBaoLotteryModule.class).lottery(reqMsg.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret > 0) {
            YuanBaoLotteryProto.YuanBaoLotteryGetRespMsg.Builder builder = YuanBaoLotteryProto.YuanBaoLotteryGetRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(Protocol.S_YUANBAO_LOTTERY_GET % 20000, builder);
        }
    }
}
